import sys
sys.path.insert(0,'../')
from RestAPI.amazon.S3 import  LifeCycleRules,Bucket
from RestAPI.core.APIExceptions import *
import unittest
from setting import *

class testLifeCycleRules(unittest.TestCase):
    def test1(self):
        conf1=LifeCycleRules("""<LifecycleConfiguration>
  <Rule>
    <ID>delete-all-in-30-days-rule</ID>
    <Prefix></Prefix>
    <Status>Enabled</Status>
    <Expiration>
      <Days>3650</Days>
    </Expiration>
  </Rule>
</LifecycleConfiguration>
        """)
        conf1.addRule("test/","245 days","new-rule-1")
        conf1.addRule("test/","245 days")
        conf1.addRule("","245 days","new-rule-that-override-delete-all-in-30-days-rule")
        conf1.addRule("test/","2 weeks","delete-all-in-30-days-rule")
        conf2=LifeCycleRules()
        conf2.addRule("test/","245 days","new-rule-1")
        print conf1.content()
        print conf2.content()
    def test2(self):
        bucket=Bucket('p4th')
        bucket.setCredential(AUTHID,AUTHKEY)
        LifecycleConfiguration=bucket.getLifeCycleRules()
        print LifecycleConfiguration.content()
        #`LifecycleConfiguration.addRule("test","1 days",id="test-rule1")
        print LifecycleConfiguration.content()
        bucket.updateLifeCycleRules(LifecycleConfiguration)

if __name__ == '__main__':
    unittest.main()
